package com.lanou.renrenxin.adapter;

import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.lanou.renrenxin.R;

import java.util.ArrayList;

/**
 * Created by zy on 16/3/2.
 */
public class TabAdapter extends FragmentPagerAdapter{
    private ArrayList<Fragment> fragments;
    private Context context;
    String title1 = "聊天";
    String title2 = "朋友";
    String title3 = "个人";
    String title4 = "设置";
    String[] titles = {title1,title2,title3,title4};
    int[] picturls = {R.drawable.select_chat,R.drawable.select_friends,
            R.drawable.select_personal,R.drawable.select_set};

    public TabAdapter(FragmentManager fm, ArrayList<Fragment> fragments, Context context) {
        super(fm);
        this.fragments = fragments;
        this.context = context;
    }

    @Override
    public Fragment getItem(int position) {
        return fragments.get(position);
    }

    @Override
    public int getCount() {
        return fragments.size();
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return null;
    }
    public View getTabView(int position){
        View view = LayoutInflater.from(context).inflate(R.layout.tablayout,null);
        TextView textView = (TextView) view.findViewById(R.id.tv_tablayout);
        ImageView imageView = (ImageView) view.findViewById(R.id.iv_tablayout);
        imageView.setImageResource(picturls[position]);
        textView.setText(titles[position]);
        return view;
    }
}
